﻿#include "client_simulator/rtsp_client_manager.h"
#include <thread>

static void RtspThreadFunction(Config::Ptr config) {
  EventLoop::Ptr event_loop(new EventLoop());
  if (!event_loop->Initialize()) {
    return;
  }

  RtspClientManager::Ptr manager(new RtspClientManager(config, event_loop));
  manager->Start();

  event_loop->Run();

  std::cout << "rtsp_done" << std::endl;

  event_loop->Uninitialize();
}

static void http_thread_func() {
  // HttpServer::Ptr http_server(new HttpServer());
}

int main(int argc, char *argv[]) {
  Config::Ptr config(new Config());
  if (!config->Parse("client_simulator.json")) {
    return -1;
  }

  if (!InitializeNet()) {
    std::cout << "Initialize network failed!" << std::endl;
    return false;
  }

  DeleteDirectory("results");
  MakeDirectory("results");

  std::thread rtsp_thread(RtspThreadFunction, config);
  // std::thread http_thread(http_thread_func);

  rtsp_thread.join();
  // http_thread.join();

  FILE *file = fopen("status_client_simulator_done", "w");
  fclose(file);

  UninitializeNet();
  return 0;
}
